package com.wsoft.controller;

import com.wsoft.query.module.ModuleIdQuery;
import com.wsoft.query.module.ModuleInsertQuery;
import com.wsoft.query.module.ModuleListQuery;
import com.wsoft.query.module.ModuleUpdateQuery;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import com.wsoft.service.ITsModuleService;
import com.wsoft.vo.ModuleNameVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 模块表 前端控制器
 * @author Z001
 * @since 2024年12月17日 09:48:45
 */
@RestController
@Tag(name = "模块")
@RequestMapping("/module")
public class TsModuleController {

    @Resource
    private ITsModuleService moduleService;


    @Operation(summary = "新增模块", description = "新增模块")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid ModuleInsertQuery query) {
        boolean b = moduleService.insertModule(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改模块", description = "修改模块")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid ModuleUpdateQuery query) {
        boolean b = moduleService.updateModule(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "详情页面", description = "详情页面")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(moduleService.getModuleInfo(id));
    }

    @Operation(summary = "删除模块", description = "删除模块")
    @GetMapping("/delete")
    public ResponseResult dropModule(@RequestParam("id") Long id) {
        boolean b = moduleService.deleteModule(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "查询模块列表", description = "查询模块列表")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ModuleListQuery query) {
        return ResponseResult.success(ResponsePage.restPage(moduleService.listModule(query)));
    }


    @Operation(summary = "获取模块名称", description = "获取模块名称")
    @PostMapping("/getModuleName")
    public ResponseResult getModuleName(@RequestBody ModuleIdQuery query) {
        List<ModuleNameVO> list  = moduleService.getModuleName(query);
        return ResponseResult.success(list);
    }

    @Operation(summary = "查询模块列表-不分页", description = "查询模块列表-不分页")
    @PostMapping("/listAll")
    public ResponseResult listAll() {
        return ResponseResult.success(moduleService.listAll());
    }
}
